Thread control method and apparatus, and communication device and system
By calling the driver module outside the operating system for thread control through the CPU, and using blocking wake-up or polling operations, the problem of high delay in data acquisition by application threads in the existing technology is solved, and more efficient data acquisition and resource utilization are achieved.
Patent Information
- Application Number
- PCT/CN2024/089210
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-04-28
- Filing Date
- 2024-04-22
- Publication Date
- 2024-10-31
AI Technical Summary
In the existing technology, when the CPU controls the application thread to obtain data outside the communication device, it relies on the virtual file system, resulting in a single control method and high latency, which cannot meet microsecond-level requirements.
The CPU calls the driver module outside the operating system to perform thread control operations, obtains target data through direct memory access, and uses blocking wake-up operations or polling operations to optimize thread control and reduce dependence on the virtual file system.
It enriches the control method of application threads, reduces the complexity and time for the CPU to call the virtual file system, reduces the delay in obtaining data through the network card, and improves the efficiency of data acquisition and CPU resource utilization.
Smart Images

Figure CN2024089210_31102024_PF_FP_ABST
Abstract
Description
Thread control method and device, communication equipment and system
[0001] This application claims priority to Chinese patent application filed on April 28, 2023, with application number 202310490908.4 and application name “Thread control method and device, communication equipment and system”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of communication technology, and in particular to a thread control method and apparatus, communication equipment and system. Background Art
[0003] A communication device generally includes a central processing unit (CPU) and a network card. An application thread running on the CPU can control the network card to communicate with other devices outside the communication device to obtain data.
[0004] In related technology, when an application thread controls a network card to retrieve data from a device other than a communication device, the CPU invokes the virtual file system in the operating system to block the application thread, causing it to cease execution. Once the network card retrieves the data, the CPU invokes the virtual file system to wake up the blocked application thread, allowing it to run and retrieve the data. This shows that when an application thread needs to retrieve data from a device other than a communication device through the network card, the CPU can invoke the virtual file system to control the application thread, enabling it to retrieve the data.
[0005] However, the current method for the CPU to control application threads is relatively simple.
[0006] Summary of the Invention
[0007] This application provides a thread control method and apparatus, a communication device, and a system, which can solve the problem of a relatively single control method for application threads. The technical solution is as follows:
[0008] In the first aspect, the present application provides a thread control method, which includes: when the CPU is running an application thread and the application thread needs to obtain target data, calling a driver module outside the operating system to perform a thread control operation so that the application thread reads the target data from the memory; wherein, the CPU is connected to the network card, and the network card is used to obtain target data from the target device under the control of the application thread, and store the target data in the memory through direct memory access.
[0009] In the method provided in the embodiments of the present application, when an application thread needs to obtain target data, the CPU can call a driver module outside the operating system to control the application thread so that the application thread obtains the target data. This eliminates the need for the CPU to call the virtual file system in the operating system to control the application thread, thereby enriching the control methods of the application thread.
[0010] Optionally, the call stack of the driver module is shorter than the call stack of the virtual file system in the operating system. In this way, the complexity of the CPU calling the driver module is lower than the complexity of calling the virtual file system, which can facilitate the CPU calling the driver module in a shorter time than the time of calling the virtual file system. In this application, the CPU calls the driver module to control the application thread, thereby bypassing the virtual file system in the operating system, thereby further reducing the delay of the application thread in obtaining the target data through the network card. It is understandable that the call stack of the driver module may not be shorter than the call stack of the virtual file system in the operating system, and this application does not limit this.
[0011] Optionally, the CPU is configured to run an application thread when the application thread is at the head of a CPU run queue. In this case, the thread control operation includes a blocking wakeup operation or a polling operation. The blocking wakeup operation includes removing the application thread from the CPU run queue and, based on an interrupt message sent by the network card indicating that the target data has been stored in the memory, adding the application thread to the CPU run queue. The polling operation includes adding the application thread to the CPU run queue. After joining the CPU run queue, if the application thread is at the head of the CPU run queue, the application thread will run again, and when the application thread runs again, it will read the target data from the memory.
[0012] In addition, in this application, the thread control operation includes a blocking wake-up operation or a polling operation as an example. It can be understood that the thread control operation can also be an operation different from the blocking wake-up operation and the polling operation, and this application does not limit this.
[0013] Optionally, the blocking wake-up operation also includes: after the application thread is taken out of the CPU run queue, the application thread is added to the waiting queue. In this case, the interrupt message carries the identifier of the target completion queue (CQ); when the CPU adds the application thread to the CPU run queue based on the interrupt message, it can determine the application thread corresponding to the target CQ in the waiting queue based on the identifier of the target CQ carried by the interrupt message and the CQ corresponding to each application thread in the CPU run queue, and add the application thread to the CPU run queue. It is understandable that in this application, the CPU may not add the application thread to the waiting queue.
[0014] Furthermore, when the CPU adds an application thread to a CPU run queue based on an interrupt message, it can add the application thread to any position in the CPU run queue, such as at the head of the queue. This allows the application thread to be executed quickly, thereby improving the efficiency of the application thread in acquiring target data and reducing the latency for the first application to acquire target data through the network card.
[0015] Optionally, in the case where the thread control operation includes a blocking wake-up operation or a polling operation, the CPU may call the driver module to perform the blocking wake-up operation when calling the driver module to determine that the execution condition of the blocking wake-up operation is met; and, when calling the driver module to determine that the execution condition of the blocking wake-up operation is not met, call the driver module to perform the polling operation; the CPU may also call the driver module to send an operation indication message to the network card, the operation indication message being used to indicate that the thread control operation is the blocking wake-up operation or the polling operation; the network card is used to send the interrupt message to the CPU based on the operation indication information to indicate that the thread control operation is the blocking wake-up operation.
[0016] For example, the execution condition of the blocking wake-up operation includes: the frequency of the application thread reading data from the memory in the most recent target time period is less than a frequency threshold, and / or the load of the CPU is greater than a load threshold.
[0017] If the frequency of an application thread reading data from the memory within the recent target time period is lower than the frequency threshold, it indicates that the application thread has recently frequently obtained data from the memory. In this case, using a blocking wake-up operation will affect the efficiency of the application thread in obtaining data. Therefore, using a polling operation to control the application thread as much as possible can improve the efficiency of the application thread in obtaining data.
[0018] If the frequency of the application thread reading data from the memory within the recent target time period is greater than or equal to the frequency threshold, it indicates that the application thread has recently obtained data from the memory less frequently. In this case, using the blocking wakeup operation will not affect the efficiency of the application thread in obtaining data. Try to use the blocking wakeup operation to control the application thread to improve CPU utilization.
[0019] When the CPU load is greater than the load threshold, it indicates that the CPU load is high. In this case, using a blocking wake-up operation will minimize the impact on the CPU load. Therefore, the blocking wake-up operation is used as much as possible to control the application thread.
[0020] When the CPU load is less than or equal to the load threshold, it indicates that the CPU load is low. In this case, using a blocking wake-up operation will affect the efficiency of the application thread in obtaining data. Therefore, using a polling operation to control the application thread as much as possible can improve the efficiency of the application thread in obtaining data.
[0021] The execution conditions of the blocking wake-up operation may also be different from the conditions in the above content, and the embodiments of the present application are not limited to this.
[0022] In the above description, the CPU calls the driver module to determine whether to use a blocking wakeup operation or a polling operation in the thread control operation for the application thread based on whether the execution conditions of the blocking wakeup operation are met. It is understood that the CPU calling the driver module may also not determine whether the execution conditions are met, but instead use a blocking wakeup operation or a polling operation for the application thread by default.
[0023] The CPU can determine that the application thread needs to obtain the target data in a variety of ways. For example, when the application thread controls the network card to obtain the target data, or when the application thread fails to read the target data from the memory, the CPU can determine that the application thread needs to obtain the target data. The CPU can also determine that the application thread needs to obtain the target data in other ways. For example, the CPU can analyze the execution process of the application thread in advance to determine that the application thread needs to obtain the target data at a certain time in the future. When the time arrives, the CPU can determine that the application thread needs to obtain the target data. It can be seen that the CPU can also determine that the application thread needs to obtain the target data by prediction.
[0024] In a second aspect, the present application also provides a data acquisition method, the method comprising: a network card, under the control of an application thread running on a CPU, acquiring target data from a target device and storing the target data in a memory via direct memory access; the network card may also receive an operation indication message sent by the CPU, the operation indication message being used to indicate that the thread control operation is a blocking wake-up operation or a polling operation; thereafter, based on the operation indication information indicating that the thread control operation is the blocking wake-up operation, the network card sends an interrupt message to the CPU indicating that the target data has been stored in the memory. The CPU is configured to run the application thread when the application thread is at the head of a CPU run queue, and, when the running application thread needs to obtain the target data, call a driver module outside the operating system to perform the thread control operation so that the application thread reads the target data from the memory; the blocking wake-up operation includes removing the application thread from the CPU run queue and, based on the interrupt message, adding the application thread to the CPU run queue; the polling operation includes adding the application thread to the CPU run queue; and the application thread is configured to read the target data from the memory when it runs again.
[0025] In a third aspect, the present application also provides a thread control device, which is a CPU, the CPU is connected to a network card, and the thread control device includes various modules for executing the thread control method described in any design in the first aspect.
[0026] In a fourth aspect, the present application further provides a data acquisition device, which is a network card connected to a central processing unit (CPU). The data acquisition device includes: various modules for executing the thread control method described in the second aspect.
[0027] In a fifth aspect, a CPU is provided, which is used to execute the thread control method described in any design in the first aspect.
[0028] In a sixth aspect, a network card is provided, which is used to execute the data acquisition method described in the second aspect.
[0029] In the seventh aspect, a communication device is provided, including: a CPU and a network card, the CPU is connected to the network card, the CPU is the thread control device described in the third aspect or the CPU described in the fifth aspect, and the network card is the data acquisition device described in the fourth aspect or the network card described in the sixth aspect.
[0030] In an eighth aspect, a communication system is provided, comprising: the communication device described in the seventh aspect, and a target device, wherein the network card in the communication device is used to obtain data from the target device.
[0031] In a ninth aspect, the present application further provides a readable storage medium having instructions stored therein, which, when executed on a CPU, causes the CPU to execute the method described in any one of the designs of the first aspect. When executed on a network card, the network card executes the method described in the second aspect.
[0032] In a tenth aspect, the present application further provides a program product comprising instructions, which, when executed on a CPU, causes a network card to execute the method described in any one of the first aspects. When executed on a network card, the program product causes the network card to execute the method described in the second aspect.
[0033] The effects of the second to tenth aspects mentioned above can refer to the effects of the corresponding designs in the first aspect, and this application will not go into details here. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] FIG1 is a schematic diagram of a communication system provided by the present application;
[0035] FIG2 is a schematic diagram of a thread running time provided by the present application;
[0036] FIG3 is a schematic diagram of another thread running time provided by the present application;
[0037] FIG4 is a schematic diagram of a communication device provided in an embodiment of the present application;
[0038] FIG5 is a flowchart of a thread control method provided in an embodiment of the present application;
[0039] FIG6 is a schematic structural diagram of a thread control device provided in an embodiment of the present application;
[0040] FIG7 is a schematic structural diagram of a data acquisition device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0041] In order to make the principles and technical solutions of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0042] As shown in Figure 1, the present application provides a communication system, which includes: a communication device 01 and a target device 02. Communication device 01 can be any device including a CPU 011 and a network card 012 (such as a server, switch, terminal, or any other device with communication capabilities). Target device 02 can be a network device, a storage device, or an accelerator (such as a graphics processing unit (GPU) or a neural processor unit (NPU)). The communication system can be a data center network, a storage network, etc.
[0043] In the communication device 01, the network card 012 can obtain target data from the target device 02 under the control of the application thread running in the CPU 011. After the network card 012 obtains the target data, the application thread running on the CPU 011 can read the target data and process the target data.
[0044] In the embodiment of the present application, the target device 02 is taken as an example where it is located outside the communication device 01. It is understandable that the target device 02 may also belong to the communication device 01, and the embodiment of the present application does not limit this.
[0045] With the advancement of technology, data center and storage network latency has entered the microsecond era. Accelerators such as GPUs and NPUs also require microsecond-level fine-grained task offloading. Application threads running in the CPU must achieve microsecond latency when accessing target data through the network interface card (NIC). However, due to technological limitations, the latency for application threads running in the CPU to access target data through the NIC is currently high, failing to meet microsecond requirements.
[0046] For example, when a first application thread controls a network card to retrieve target data from a target device other than a communication device, the CPU invokes a virtual file system in the operating system to block the first application thread, causing it to cease execution. After the network card retrieves the target data, the CPU invokes the virtual file system to awaken the blocked first application thread, allowing it to run and retrieve the target data. Furthermore, while the first application thread is blocked, the CPU executes a second application thread in addition to the first application thread, and awakens the first application thread after the second application thread completes execution.
[0047] As shown in Figure 2, assuming the network card acquires the target data for a first duration and the second application thread runs for a second duration, and the first and second durations are relatively close, the second application thread will have almost completed execution after the network card acquires the target data. This allows the CPU to run the second application thread during the period between the first application thread being blocked and the first application thread being awakened, without significantly impacting the first application thread.
[0048] However, as shown in FIG3 , when the first duration is a relatively short microsecond duration, if the second duration is relatively long and the difference between the second duration and the first duration is relatively large, then after the network card obtains the target data, the first application thread needs to wait for the second application thread to run for a relatively long time before being awakened. As a result, the duration for the first application thread to obtain the target data through the network card cannot reach the microsecond level.
[0049] Furthermore, the call stack of the virtual file system in the operating system is typically long, and the CPU takes a long time to call the virtual file system, which further prolongs the time it takes for the first application thread to retrieve the target data through the network card. Furthermore, the method used in related art for the CPU to call the virtual file system to control application threads is relatively simple, requiring a new control method.
[0050] Furthermore, in the related art, the CPU can also control the first application thread without calling the virtual file system. For example, when the first application thread controls the network card to obtain target data, the CPU will continue to run the first application thread and wait for the target data to be obtained by the network card; after the network card obtains the target data, the first application thread processes the target data. After the first application thread stops running, the CPU runs other application threads on the resources (CPU core) running the first application thread. However, in this method, during the time period between the first application thread controlling the network card to obtain target data and the network card obtaining the target data, the resources in the CPU running the first application thread are equivalent to being idle, resulting in low CPU resource utilization.
[0051] Embodiments of the present application provide a thread control method in which the CPU controls application threads by invoking a driver module outside the operating system, rather than a virtual file system. This method enriches the control methods for application threads. Furthermore, this method enables application threads to quickly acquire target data while ensuring high CPU resource utilization.
[0052] Before describing the thread control method provided by the embodiments of the present application, the embodiments of the present application will first briefly describe the application scenarios of the method. For example, as shown in Figure 4, a communication device includes a CPU, a network card, and memory. The CPU includes a user-mode portion and a kernel-mode portion, wherein the user-mode portion includes an application, and the kernel-mode portion includes an operating system and a driver module. The network card can be a programmable network card, such as a remote direct memory access (RDMA) network card.
[0053] The CPU can call the driver module. When the CPU does not call the driver module, the driver module is located outside the operating system, making it independent of the operating system. When the CPU calls the driver module, the driver module can run on the operating system. Thus, the driver module is independent of the operating system, while the virtual file system mentioned above belongs to the operating system. When the CPU does not call the virtual file system, it resides within the operating system.
[0054] After the application thread of the application controls the network card to obtain target data from a target device outside the communication device, the network card can store the obtained target data to the memory (such as to a data buffer or other storage area in the memory) through direct memory access (DMA). The driver module outside the above-mentioned operating system is used to control the application thread so that the application thread can read the target data from the memory after controlling the network card to obtain the target data. When the CPU is running the application thread and the application thread needs to obtain the target data, it can call the driver module to perform thread control operations to enable the application thread to read the target data from the memory.
[0055] For example, FIG5 is a flowchart of a thread control method provided in an embodiment of the present application. As shown in FIG5 , the method includes:
[0056] S101: When a CPU executes an application thread and the application thread controls a network card to obtain target data, the CPU calls a driver module outside the operating system to determine whether the execution conditions for a blocking wakeup operation are met. If the execution conditions for the blocking wakeup operation are met, S102 is executed; if the execution conditions for the blocking wakeup operation are not met, S104 is executed.
[0057] An application thread can be any thread in any application. An application thread is placed in a CPU run queue. Threads in the CPU run queue run sequentially according to the queue order. When an application thread is at the head of the CPU run queue, the CPU runs the application thread. It is understood that the CPU can also run application threads independently of the CPU run queue. For example, the CPU can simultaneously run multiple application threads, including the application thread.
[0058] When an application thread is running and needs to obtain target data from a target device, the application thread can call an interface of a driver module outside the operating system to control the network card to obtain the target data through the driver module. In this way, the CPU can determine whether the application thread controls the network card to obtain the target data by detecting whether the application thread has called this interface of the driver module.
[0059] When the CPU runs the application thread and the application thread controls the network card to obtain target data, the CPU can also call the driver module to determine whether the execution condition of the blocking wake-up operation is met to determine what control operation to perform on the application thread.
[0060] The execution conditions of the blocking wake-up operation include: the frequency of the application thread reading data from the memory in the most recent target time period is less than a frequency threshold, and / or the CPU load is greater than a load threshold.
[0061] When the frequency of the application thread reading data from the memory within the recent target time period is less than the frequency threshold, it means that the application thread has recently frequently obtained data from the memory. In this case, using a blocking wake-up operation will affect the efficiency of the application thread in obtaining data. Therefore, try to use S104 to control the application thread to improve the efficiency of the application thread in obtaining data.
[0062] When the frequency of the application thread reading data from the memory within the recent target time period is greater than or equal to the frequency threshold, it means that the frequency of the application thread recently obtaining data from the memory is low. In this case, using the blocking wake-up operation will not affect the efficiency of the application thread in obtaining data. Try to use S102 to S103 to control the application thread to improve CPU utilization.
[0063] When the CPU load is greater than the load threshold, it indicates that the CPU load is high. In this case, using a blocking wake-up operation will minimize the impact on the CPU load. Therefore, the method from S102 to S103 is used as much as possible to control the application thread.
[0064] When the CPU load is less than or equal to the load threshold, it means that the CPU load is low. In this case, the blocking wake-up operation will affect the efficiency of the application thread in obtaining data. Therefore, try to use S104 to control the application thread to improve the efficiency of the application thread in obtaining data.
[0065] The execution conditions of the blocking wake-up operation may also be different from the conditions in the above content, and the embodiments of the present application are not limited to this.
[0066] S102: The CPU calls the driver module to remove the application thread from the CPU run queue. Execute S103.
[0067] As can be seen from the above, when the conditions for executing a blocking wakeup operation are met, the CPU will perform a blocking wakeup operation on the application thread using the method of S102 to S103. In S102, the CPU will call the driver module to remove the application thread from the CPU run queue, thereby blocking the application thread and stopping its execution. In this case, the CPU can run other threads in the CPU run queue to improve CPU utilization.
[0068] Optionally, the blocking wake-up operation further includes: after the CPU calls the driver module to remove the application thread from the CPU run queue, it can also call the driver module to add the application thread to a waiting queue within the driver module. The threads in the waiting queue are used to wait for the network card to obtain data. The CPU can also call the driver module without adding the application thread to the waiting queue, which is not limited in this embodiment of the application.
[0069] S103 : Based on the interrupt message sent by the network card indicating that the target data has been stored in the memory, the CPU calls the driver module to add the application thread to the CPU running queue.
[0070] After acquiring the target data, the network card will use DMA to store the target data in the memory and send an interrupt message to the CPU to indicate that the target data has been stored in the memory.
[0071] It is understandable that after determining whether the execution conditions of the blocking wake-up operation are met in the above S101, the CPU can also call the driver module to send an operation indication message to the network card, and the operation indication message is used to indicate whether the thread control operation is a blocking wake-up operation or a polling operation. When the execution conditions of the above blocking wake-up operation are met, the operation indication message is used to indicate that the thread control operation is a blocking wake-up operation; when the execution conditions are not met, the operation indication message is used to indicate that the thread control operation is a polling operation. In this way, the network card can be used to send an interrupt message to the CPU based on the operation indication information indicating that the thread control operation is a blocking wake-up operation. The operation indication message can be sent to the network card as an independent message or carried in other messages and sent to the network card. This embodiment of the present application does not limit this. In addition, when the execution conditions of the blocking wake-up operation are not met, the operation indication message sent by the CPU to the network card is used to indicate that the thread control operation is a polling operation. In this way, the network card can be used to indicate that the thread control operation is a polling operation based on the operation indication information, and not send an interrupt message to the CPU. It can be seen that in the thread control method provided in the embodiment of the present application, the network card can execute the corresponding data acquisition method (including acquiring target data, storing target data in memory, sending interrupts to the CPU, etc.) according to the instructions of the CPU.
[0072] After receiving the interrupt message, the CPU can call the driver module based on the interrupt message to add the application thread retrieved in S101 to the CPU run queue (e.g., to the end of the CPU run queue or any position other than the end). After the application thread is added to the CPU run queue, when the application thread is again at the head of the CPU run queue, the CPU will run the application thread again to enable the application thread to read the target data from the memory.
[0073] Optionally, each thread has a corresponding CQ. Different threads can have the same or different CQs. After storing the target data in memory, the network card can also fill in the target CQ corresponding to the application thread with the target data's memory storage information. When the application thread runs again, it can read the target data from memory based on the storage information in its corresponding target CQ.
[0074] The interrupt message may also carry the identifier of the target CQ corresponding to the application thread. If the CPU calls the driver module in S102 to add the application thread to the driver module's waiting queue, then in S103, the CPU calls the driver module to determine the application thread corresponding to the target CQ in the waiting queue based on the identifier of the target CQ carried in the interrupt message and the correspondence between each application thread and CQ in the CPU's run queue. Thereafter, the application thread is added to the CPU's run queue.
[0075] It is understood that when multiple application threads in the waiting queue correspond to a target CQ, the CPU will receive multiple interrupt messages carrying the identifier of the target CQ. These multiple interrupt messages correspond one-to-one with these multiple application threads, and the CPU can add these multiple application threads to the CPU run queue based on these multiple interrupt messages. If there is only one application thread in the waiting queue, the CPU can also call the driver module to determine the application thread corresponding to the target CQ identifier and add this application thread to the CPU run queue.
[0076] S104: The CPU calls the driver module to add the application thread to the CPU run queue.
[0077] As can be seen from the above, when the execution conditions of the blocking wake-up operation are not met, the CPU will perform a polling operation on the application thread in the manner of S104. The polling operation includes: adding the application thread to the CPU run queue (adding it to any position of the CPU run queue, such as the end of the queue). After the application thread is added to the CPU run queue, the application thread will wait until it is again at the head of the CPU run queue before running.
[0078] It is understandable that after the polling operation is performed on the application thread, when the application thread runs again, if the network card has written the target data to the memory, then the application thread can read the target data from the memory. If the network card has not yet written the target data to the memory, then the application thread cannot read the target data from the memory. In this case, the CPU can determine that the application thread still needs to obtain the target data. At this time, the CPU can call the driver module again to determine whether the execution conditions of the blocking wake-up operation in S101 are met, and if the execution conditions of the blocking wake-up operation are met, execute S102; if the execution conditions of the blocking wake-up operation are not met, execute S104. Repeat this process until the application thread reads the target data from the memory.
[0079] Furthermore, in the polling operation of the embodiment of the present application, when the application thread moves to the head of the CPU run queue again, if the target data is not retrieved from the memory, the CPU will call the driver module to determine again whether a blocking wake-up operation or a polling operation is required for the first application process. This prevents the application thread from continuously occupying CPU resources due to the failure to retrieve the target data, allowing these resources to be used by other threads, improving CPU utilization and being suitable for high-throughput communication equipment scenarios.
[0080] In both S103 and S104 above, the CPU invokes the driver module to add the application thread to the CPU run queue. In this case, the driver module adds the application thread to an appropriate position in the CPU run queue based on some mechanism. The appropriate position can be any position in the CPU run queue. For example, if the threads in the CPU run queue are arranged in order of priority, the driver module can add the application thread to the CPU run queue based on the priority of the application thread.
[0081] According to the above content, in the method provided in the embodiment of the present application, the CPU calling driver module can perform thread control operations (blocking wake-up operations or polling operations) on the application thread when the CPU runs the application thread and the application thread needs to obtain target data, so that the application thread can finally obtain the target data.
[0082] In summary, in the method provided in the embodiments of the present application, when an application thread needs to obtain target data, the CPU can call a driver module outside the operating system to control the application thread, thereby enabling the application thread to obtain the target data. This eliminates the need for the CPU to call the virtual file system in the operating system to control the application thread, thereby enriching the control methods for the application thread.
[0083] Furthermore, when the CPU invokes the driver module in S103 to add the application thread to the CPU run queue based on the interrupt message, the application thread can be added to any position in the CPU run queue, such as at the head of the CPU run queue. This allows the application thread to be quickly executed without waiting for the currently running thread to complete, thereby improving the efficiency of the application thread in acquiring target data and reducing the latency for the first application to acquire target data through the network card.
[0084] The correspondence between the application thread and the target CQ is required in S103. Before S103 (e.g., when the application to which the application thread belongs is initialized), the application thread can register the target CQ corresponding to the application thread with the driver module, for example, by sending a structure representing the application thread and the target CQ corresponding to the application thread to the driver module.
[0085] An application thread can be any thread in a process of the application to which it belongs. The application can register the CQ corresponding to each thread in the process on the driver module during initialization. Information corresponding to each process can be registered on the driver module. The information corresponding to each process includes: the waiting queue corresponding to the process, and the CQ corresponding to each thread in the process. After being taken out of the CPU running queue, the application thread can be added to the waiting queue corresponding to the process to which the application thread belongs, and based on the correspondence between the thread and the CQ in the information corresponding to the process, the application thread corresponding to the target CQ can be determined. After the CPU calls the driver module to add the application thread to the CPU running queue, it can delete the application thread from the above-mentioned waiting queue.
[0086] In addition, the information corresponding to each process may also include an event list. The driver module may record the identifier of the target CQ in the event list, and after determining the application thread based on the identifier of the target CQ and adding the application thread to the CPU run queue, the identifier of the target CQ may also be deleted from the event list.
[0087] In some cases, if the application thread continuously controls the network card to obtain different target data, the network card will continuously send two interrupt messages to the application thread, and both interrupt messages carry the identifier of the target CQ corresponding to the application thread. In this case, the event list can record the identifiers of the two target CQs. After the CPU calls the driver module based on the first interrupt message to add the application thread to the CPU running queue, the application thread has been deleted from the waiting queue, and the identifier of one target CQ has also been deleted from the event list. At this time, the CPU cannot find the application thread in the waiting queue based on the identifier of another target CQ. In this case, the CPU can assume that the application thread has been awakened, and can call the driver module to delete the identifier of the other target CQ in the event list.
[0088] In the above embodiment, the CPU calls the driver module to determine whether to use the blocking wakeup operation or the polling operation in the thread control operation for the application thread based on whether the execution conditions of the blocking wakeup operation are met. It is understood that the CPU calls the driver module without determining whether the execution conditions are met, and instead uses the blocking wakeup operation or the polling operation for the application thread by default.
[0089] In addition, in the above embodiments, thread control operations include blocking wake-up operations or polling operations. It is understood that the thread control operation can also be an operation different from blocking wake-up operations and polling operations, and the embodiments of the present application are not limited to this. For example, the thread control operation can be to continuously run the application thread so that the application thread continuously reads data from the memory until the target data is read.
[0090] The driver module and the virtual file system are both programs, and the program has a call stack, and the length of the program's call stack is positively correlated with the complexity of the CPU calling the program. When the program's call stack is shorter, the complexity of the CPU calling the program is lower. When the program's call stack is longer, the complexity of the CPU calling the program is higher. Optionally, the driver module's call stack is shorter than the virtual file system's call stack in the operating system. In this way, the complexity of the CPU calling the driver module is lower than the complexity of calling the virtual file system, which can facilitate the realization that the time for the CPU to call the driver module is shorter than the time for calling the virtual file system. In this application, the CPU calls the driver module to control the application thread, thereby being able to bypass the virtual file system in the operating system, thereby further reducing the delay for the application thread to obtain target data through the network card. It is understandable that the driver module's call stack may also be no shorter than the virtual file system's call stack in the operating system, and this is not limited in the embodiments of the present application.
[0091] The method provided in the embodiments of the present application is equivalent to adding a driver module to the core of the CPU. The CPU controls the application thread by calling the driver module. Moreover, because the driver module is outside the operating system, the present application does not need to change the operating system and can flexibly design the driver module as needed.
[0092] 4, the operating system may include an interrupt processing module and a scheduling module. The interrupt processing module is used to process interrupt messages sent by the network card, and the scheduling module is used to schedule threads using a certain strategy to select a thread to run.
[0093] The driver module in the embodiment of the present application can register the interrupt processing function of the driver module in the interrupt processing module. In this way, in the above S103, the interrupt processing module in the CPU can call the interrupt processing function of the driver module based on the interrupt message to add the application thread to the CPU running queue.
[0094] In the above S104 , when the CPU calls the driver module to add the application thread to the CPU run queue, the driver module may further call the scheduling module to schedule the application thread to add the application thread to the CPU run queue.
[0095] In S103 above, when the CPU calls the driver module based on the interrupt message to add the application thread to the CPU run queue, the driver module can further call the scheduling module to complete the scheduling of the application thread. For example, the driver module can send a rescheduling message to the scheduling module, which carries the application thread and a rescheduling flag. The scheduling module can then add the application thread to the CPU run queue based on the rescheduling message.
[0096] Based on the thread control method provided in this application, this application also provides a thread control device. The thread control device is the above-mentioned CPU, and the CPU is connected to a network card. As shown in FIG6 , the thread control device includes:
[0097] The first calling module 601 is configured to, when the CPU is running an application thread and the application thread needs to obtain target data, call a driver module outside the operating system to perform thread control operations, so that the application thread reads the target data from the memory; wherein, under the control of the application thread, the network card is configured to obtain the target data from the target device and store the target data in the memory via direct memory access (DMA). The operations performed by the first calling module 601 can refer to the operations performed by the CPU in S102, S103, and S104 of the aforementioned embodiment.
[0098] In summary, in the thread control device provided in the embodiments of the present application, the first calling module can, when an application thread needs to obtain target data, call a driver module outside the operating system to control the application thread, thereby enabling the application thread to obtain the target data. This eliminates the need for the CPU to call the virtual file system in the operating system to control the application thread, thereby enriching the control methods for the application thread.
[0099] Optionally, the driver module's call stack is shorter than the operating system's virtual file system's call stack. This allows the CPU to call the driver module in less time than the virtual file system. In this application, the CPU calls the driver module to control the application thread, thereby bypassing the operating system's virtual file system. This further reduces the latency for the application thread to retrieve target data through the network card. It is understood that the driver module's call stack may not be shorter than the operating system's virtual file system's call stack, and this application does not impose any restrictions on this.
[0100] Optionally, the CPU is configured to run an application thread when the application thread is at the head of a CPU run queue. In this case, the thread control operation includes a blocking wakeup operation or a polling operation. The blocking wakeup operation includes removing the application thread from the CPU run queue and, based on an interrupt message sent by the network card indicating that the target data has been stored in the memory, adding the application thread to the CPU run queue. The polling operation includes adding the application thread to the CPU run queue. After joining the CPU run queue, if the application thread is at the head of the CPU run queue, the application thread will run again, and when the application thread runs again, it will read the target data from the memory.
[0101] In addition, in this application, the thread control operation includes a blocking wake-up operation or a polling operation as an example. It can be understood that the thread control operation can also be an operation different from the blocking wake-up operation and the polling operation, and this application does not limit this.
[0102] Optionally, the blocking wake-up operation also includes: after the application thread is taken out of the CPU run queue, the application thread is added to the waiting queue. In this case, the interrupt message carries the identifier of the target completion queue (CQ); when the CPU adds the application thread to the CPU run queue based on the interrupt message, it can determine the application thread corresponding to the target CQ in the waiting queue based on the identifier of the target CQ carried by the interrupt message and the CQ corresponding to each application thread in the CPU run queue, and add the application thread to the CPU run queue. It is understandable that in this application, the CPU may not add the application thread to the waiting queue.
[0103] Furthermore, when the CPU adds an application thread to a CPU run queue based on an interrupt message, it can add the application thread to any position in the CPU run queue, such as at the head of the queue. This allows the application thread to be executed quickly, thereby improving the efficiency of the application thread in acquiring target data and reducing the latency for the first application to acquire target data through the network card.
[0104] Optionally, in the case where the thread control operation includes a blocking wake-up operation or a polling operation, the first calling module includes: a first calling unit and a second calling unit. The first calling unit is configured to call the driver module to perform the blocking wake-up operation when the driver module is called to determine that the execution condition of the blocking wake-up operation is satisfied; and the second calling unit is configured to call the driver module to perform the polling operation when the driver module is called to determine that the execution condition of the blocking wake-up operation is not satisfied. The thread control device may further include: a second calling module configured to call the driver module to send an operation indication message to the network card, the operation indication message being configured to indicate that the thread control operation is the blocking wake-up operation or the polling operation; and the network card is configured to send the interrupt message to the CPU based on the operation indication information indicating that the thread control operation is the blocking wake-up operation.
[0105] For example, the execution condition of the blocking wake-up operation includes: the frequency of the application thread reading data from the memory in the most recent target time period is less than a frequency threshold, and / or the load of the CPU is greater than a load threshold.
[0106] If the frequency of an application thread reading data from the memory within the recent target time period is lower than the frequency threshold, it indicates that the application thread has recently frequently obtained data from the memory. In this case, using a blocking wake-up operation will affect the efficiency of the application thread in obtaining data. Therefore, using a polling operation to control the application thread as much as possible can improve the efficiency of the application thread in obtaining data.
[0107] If the frequency of the application thread reading data from the memory within the recent target time period is greater than or equal to the frequency threshold, it indicates that the application thread has recently obtained data from the memory less frequently. In this case, using the blocking wakeup operation will not affect the efficiency of the application thread in obtaining data. Try to use the blocking wakeup operation to control the application thread to improve CPU utilization.
[0108] When the CPU load is greater than the load threshold, it indicates that the CPU load is high. In this case, using a blocking wake-up operation will minimize the impact on the CPU load. Therefore, the blocking wake-up operation is used as much as possible to control the application thread.
[0109] When the CPU load is less than or equal to the load threshold, it indicates that the CPU load is low. In this case, using a blocking wake-up operation will affect the efficiency of the application thread in obtaining data. Therefore, using a polling operation to control the application thread as much as possible can improve the efficiency of the application thread in obtaining data.
[0110] The execution conditions of the blocking wake-up operation may also be different from the conditions in the above content, and the embodiments of the present application are not limited to this.
[0111] In the above description, the CPU calls the driver module to determine whether to use a blocking wakeup operation or a polling operation in the thread control operation for the application thread based on whether the execution conditions of the blocking wakeup operation are met. It is understood that the CPU calling the driver module may also not determine whether the execution conditions are met, but instead use a blocking wakeup operation or a polling operation for the application thread by default.
[0112] The CPU can determine that the application thread needs to obtain the target data in a variety of ways. For example, the thread control device also includes: a determination module (not shown in Figure 6), which is used to determine that the application thread needs to obtain the target data when the application thread controls the network card to obtain the target data, or when the application thread fails to read the target data from the memory. The CPU can also determine that the application thread needs to obtain the target data in other ways. For example, the CPU can analyze the execution process of the application thread in advance to determine that the application thread needs to obtain the target data at a certain moment in the future. When the moment arrives, the CPU can determine that the application thread needs to obtain the target data. It can be seen that the CPU can also determine that the application thread needs to obtain the target data by prediction.
[0113] Based on the thread control method provided in this application, this application also provides a data acquisition device. The data acquisition device is the above-mentioned network card, which is connected to the CPU. As shown in FIG7 , the data acquisition device includes:
[0114] An acquisition module 701 is configured to acquire target data from a target device under the control of an application thread running on the CPU;
[0115] The storage module 702 is used to store the target data in a memory via direct memory access;
[0116] A receiving module 703 is configured to receive an operation instruction message sent by the CPU, where the operation instruction message is used to indicate whether the thread control operation is a blocking wake-up operation or a polling operation;
[0117] A sending module 704 is configured to send an interrupt message to the CPU indicating that the target data has been stored in the memory based on the operation indication information indicating that the thread control operation is the blocking wake-up operation;
[0118] The CPU is used to run the application thread when the application thread is at the head of the CPU running queue, and when the running application thread needs to obtain target data, call a driver module outside the operating system to perform the thread control operation so that the application thread reads the target data from the memory; the blocking wake-up operation includes: taking the application thread out of the CPU running queue, and adding the application thread to the CPU running queue based on the interrupt message; the polling operation includes: adding the application thread to the CPU running queue; the application thread is used to read the target data from the memory when it runs again.
[0119] The operations performed by the various modules in the data acquisition device can refer to the operations performed by the network card in the aforementioned embodiment, and will not be described in detail in the embodiment of the present application.
[0120] The present application also provides a readable storage medium storing instructions that, when executed on a CPU, cause the CPU to perform the operations performed by the CPU in any of the methods provided herein. The instructions, when executed on a network interface card, cause the network interface card to perform the operations performed by the network interface card in any of the methods provided herein.
[0121] The present application also provides a program product comprising instructions, which, when executed on a CPU, causes a network card to perform the operations performed by the CPU in any of the methods provided in the present application. When executed on a network card, the program product causes the network card to perform the operations performed by the network card in any of the methods provided in the present application.
[0122] In this application, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance. Unless otherwise specified, "at least one" means one or more, and "a plurality" means two or more.
[0123] The various different types of embodiments provided in the embodiments of the present application can refer to each other, and the embodiments of the present application are not limited thereto. In the corresponding embodiments provided in the present application, it should be understood that the disclosed parameter update unit, the first device, the second device, the communication system, etc. can be implemented by other configuration methods. For example, the embodiments described above are merely illustrative, for example, the division of units or modules is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or modules can be combined or integrated, or some features can be ignored or not executed.
[0124] The units described as separate components may or may not be physically separate, and the components described as units may or may not be physical units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0125] The order of the steps in the method embodiment provided in this application can be appropriately adjusted, and the steps can be increased or decreased accordingly according to the circumstances. Any technical personnel familiar with this technical field can easily think of the changed methods within the technical scope disclosed in this application, and they should be included in the scope of protection of this application, so they will not be repeated here.
[0126] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present application, and such modifications or substitutions should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. A thread control method, characterized in that: The method is executed by a central processing unit (CPU), the CPU is connected to a network card, and the method includes: When the CPU runs an application thread and the application thread needs to obtain target data, a driver module outside the operating system is called to perform a thread control operation so that the application thread reads the target data from the memory; The network card is used to obtain the target data from the target device under the control of the application thread, and store the target data into the memory by direct memory access (DMA).
2. The method according to claim 1, characterized in that The CPU is used to run the application thread when the application thread is at the head of the CPU running queue; the thread control operation includes: blocking wake-up operation or polling operation; The blocking wake-up operation includes: taking the application thread out of the CPU run queue, and adding the application thread to the CPU run queue based on an interrupt message sent by the network card indicating that the target data has been stored in the memory; The polling operation includes: adding the application thread to the CPU run queue; The application thread is used to read the target data from the memory when the application thread runs again.
3. The method according to claim 2, characterized in that The blocking wake-up operation further includes: after taking the application thread out of the CPU run queue, adding the application thread to a waiting queue; The interrupt message carries an identifier of a target completion queue CQ; based on the interrupt message, adding the application thread to the CPU run queue includes: Determine the application thread corresponding to the target CQ in the waiting queue based on the identifier of the target CQ carried by the interrupt message and the CQs corresponding to the application threads in the CPU run queue; The application thread is added to the CPU run queue.
4. The method according to claim 2 or 3, characterized in that: Based on the interrupt message, adding the application thread to the CPU run queue includes: Based on the interrupt message, the application thread is added to the head of the CPU run queue.
5. The method according to any one of claims 2 to 4, characterized in that: Calling driver modules outside the operating system to perform thread control operations, including: When the driving module is called to determine that the execution condition of the blocking wake-up operation is met, calling the driving module to execute the blocking wake-up operation; When the driving module is called to determine that the execution condition of the blocking wake-up operation is not satisfied, calling the driving module to perform the polling operation; The method further comprises: The driver module is called to send an operation indication message to the network card, wherein the operation indication message is used to indicate that the thread control operation is the blocking wake-up operation or the polling operation; the network card is used to send the interrupt message to the CPU based on the operation indication information used to indicate that the thread control operation is the blocking wake-up operation.
6. The method according to claim 5, characterized in that The execution condition of the blocking wake-up operation includes: the frequency of the application thread reading data from the memory in the most recent target time period is less than a frequency threshold, and / or the load of the CPU is greater than a load threshold.
7. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: When the application thread controls the network card to obtain the target data, or when the application thread fails to read the target data from the memory, it is determined that the application thread needs to obtain the target data.
8. A data acquisition method, characterized in that: It is characterized in that The method is performed by a network card, the network card is connected to a central processing unit (CPU), and the method includes: Under the control of the application thread running on the CPU, the target data is obtained from the target device; Storing the target data in a memory via direct memory access (DMA); receiving an operation indication message sent by the CPU, wherein the operation indication message is used to indicate that the thread control operation is a blocking wake-up operation or a polling operation; Based on the operation indication information indicating that the thread control operation is the blocking wake-up operation, an interrupt message indicating that the target data has been stored in the memory is sent to the CPU; The CPU is used to run the application thread when the application thread is at the head of the CPU running queue, and, when the running application thread needs to obtain target data, call a driver module outside the operating system to perform the thread control operation, so that the application thread reads the target data from the memory; The blocking wake-up operation includes: taking the application thread out of the CPU run queue, and adding the application thread to the CPU run queue based on the interrupt message; The polling operation includes: adding the application thread to the CPU running queue; and the application thread is used to read the target data from the memory when running again.
9. A thread control device, characterized in that: The thread control device is a central processing unit (CPU), the CPU is connected to a network card, and the thread control device includes: A first calling module is used to call a driver module outside the operating system to perform a thread control operation when the CPU runs an application thread and the application thread needs to obtain target data, so that the application thread reads the target data from the memory; The network card is used to obtain the target data from the target device under the control of the application thread, and store the target data into the memory by direct memory access (DMA).
10. A data acquisition device, characterized in that: It is characterized in that The data acquisition device is a network card, which is connected to a central processing unit (CPU). The data acquisition device includes: An acquisition module, used for acquiring target data from a target device under the control of an application thread running on the CPU; A storage module, used for storing the target data into a memory via direct memory access (DMA); A receiving module, used for receiving an operation instruction message sent by the CPU, wherein the operation instruction message is used for indicating that the thread control operation is a blocking wake-up operation or a polling operation; a sending module, configured to send an interrupt message to the CPU indicating that the target data has been stored in the memory based on the operation indication information indicating that the thread control operation is the blocking wake-up operation; The CPU is used to run the application thread when the application thread is at the head of the CPU running queue, and, when the running application thread needs to obtain target data, call a driver module outside the operating system to perform the thread control operation, so that the application thread reads the target data from the memory; The blocking wake-up operation includes: taking the application thread out of the CPU run queue, and adding the application thread to the CPU run queue based on the interrupt message; The polling operation includes: adding the application thread to the CPU running queue; and the application thread is used to read the target data from the memory when running again.
11. A central processing unit (CPU), characterized in that: The CPU is used to execute the thread control method described in any one of claims 1 to 7.
12. A network card, characterized in that: The network card is used to execute the data acquisition method described in claim 8.
13. A communication device, characterized in that: include: A central processing unit (CPU) and a network card, wherein the CPU is connected to the network card, the CPU is the thread control device according to claim 9 or the CPU according to claim 11, and the network card is the data acquisition device according to claim 10 or the network card according to claim 12.
14. A communication system, characterized in that: include: The communication device as claimed in claim 13, and a target device, wherein the network card in the communication device is used to obtain data from the target device.
15. A readable storage medium, characterized in that: The readable storage medium stores instructions; When the instruction is executed on a CPU, the CPU is caused to execute the method according to any one of claims 1 to 7; When the instructions are executed on the network card, the network card is caused to execute the method as claimed in claim 8.
Citation Information
Patent Citations
Data communication method and device, equipment and storage medium
CN112817772A
Shared memory management method and device, computer equipment and storage medium
CN113485834A
Control method and operating system of electronic equipment
CN114237728A
Network card drive optimization method and device, equipment and storage medium
CN115460024A
Processor with flexible command processing
US20190324800A1
Cited By
Information equipment supervision system and method based on Internet of Things
CN119396479A
