Summary of the invention
To the one or more problems that exist in the correlation technique, the object of the present invention is to provide a kind of processing method and device that is used for that network data in zero-copy buffer queue sends and receives, with in addressing the above problem one of at least.
For realizing above-mentioned purpose; According to an aspect of the present invention; A kind of processing method that network data in zero-copy buffer queue sends that is used for is provided, and this method comprises: the contiguous memory of the predetermined size of application is as being used for the buffering area formation that message sends in NIC driver; The first address of the contiguous memory of being applied for is converted into physical address and the size of physical address and internal memory is stored in the network interface card related register; And the read pointer register and the write pointer register that in the network interface card register, are provided for the buffering area formation, when sending message, the size renewal read pointer register and the write pointer register of message, physical address and the internal memory that will send according to institute.
For realizing above-mentioned purpose; According to another aspect of the present invention; A kind of processing unit that network data in zero-copy buffer queue sends that is used for is provided; It is characterized in that device comprises: internal memory application unit is used for being used for the buffering area formation that message sends in the contiguous memory conduct of the predetermined size of NIC driver application; Converting unit is used for first address with the contiguous memory of being applied for and converts physical address into and store the size of physical address and internal memory into the network interface card related register; And register setting and updating block; Be used for being provided for the read pointer register and the write pointer register of buffering area formation at the network interface card register; When sending message, the size renewal read pointer register and the write pointer register of message, physical address and the internal memory that will send according to institute.
For realizing above-mentioned purpose; According to a further aspect of the invention; A kind of processing method that network data in zero-copy buffer queue receives that is used for is provided, and this method comprises: the contiguous memory of the predetermined size of application is as being used for the buffering area formation that message receives in NIC driver; The first address of the contiguous memory of being applied for is converted into physical address and the size of physical address and internal memory is stored in the network interface card related register; And the read pointer register and the write pointer register that in the network interface card register, are provided for the buffering area formation, when receiving message, upgrade read pointer register and write pointer register according to the size of the message that is received, physical address and internal memory.
For realizing above-mentioned purpose; According to a further aspect of the invention; A kind of processing unit that network data in zero-copy buffer queue receives that is used for is provided; Comprise: internal memory application unit is used for being used for the buffering area formation that message receives in the contiguous memory conduct of the predetermined size of NIC driver application; Converting unit is used for first address with the contiguous memory of being applied for and converts physical address into and store the size of physical address and internal memory into the network interface card related register; Register is provided with and updating block; Be used for being provided for the read pointer register and the write pointer register of buffering area formation at the network interface card register; And when receiving message, upgrade read pointer register and write pointer register according to the size of the message that is received, physical address and internal memory.
By above-mentioned at least one technical scheme of the present invention; Converting physical address to through the first address with the internal memory of being applied for stores in the related register; And when sending and receive message, upgrade the pointer position in the related register in time; Need not adopt interrupt mode notice driver data message to send and reception condition like this, and not take cpu resource, need not convert the user's space memory address to dma operation required physical address by page-size yet; And network interface card hardware at the data message of doing dma operation and transmission and reception in when storage; Not limited by page-size,, need not use buffer descriptor to carry out the management of buffering area formation such as the 4K byte.
Embodiment
Functional overview
Consider exist in the correlation technique problem; The present invention proposes to be used for processing method and the device that network data in zero-copy buffer queue sends and receives; Through applying for that continuous internal memory is as the buffering area formation of sending or receive message; Convert the first address of the internal memory of being applied for to physical address and store in the related register, and when sending or receive message, upgrade the pointer position in the related register in time, need not adopt interrupt mode notice driver data message to send or reception condition like this; And do not take cpu resource; Need not convert the user's space memory address to dma operation required physical address by page-size yet, and network interface card hardware at the data message of doing dma operation and transmission and reception in when storage, not limited by page-size; Such as the 4K byte, need not use buffer descriptor to carry out the management of buffering area formation.
Fig. 1 is the flow chart that is used for the processing method of network data in zero-copy buffer queue transmission according to of the present invention.
As shown in Figure 1, the processing method that is used for the network data in zero-copy buffer queue transmission according to the present invention may further comprise the steps:
Step S102, the contiguous memory of the predetermined size of application is as being used for the buffering area formation that message sends in NIC driver;
Step S104 converts the first address of the contiguous memory of being applied for physical address into and the size of physical address and internal memory is stored in the network interface card related register; And
Step S106 is provided for the read pointer register and the write pointer register of buffering area formation in the network interface card register, when sending message, and the size renewal read pointer register and the write pointer register of message, physical address and the internal memory that will send according to institute.
Wherein, can specify the size of the contiguous memory of being applied for, the size of the contiguous memory that also can when driver loads, be applied for through the parameter appointment through configuration file.The size of internal memory need confirm according to the memory size of computer, 32MB for example, 64MB etc.The network interface card related register can be for sending buffering area first address configuration register, and it can be 64 sizes.The network interface card register itself is exactly the memory headroom of storage 32 figure places.
When sending message, can pass through application program update write pointer register, and can upgrade read pointer register through network interface card.
When application program is sent message; Read pointer register and write pointer register are compared; If the numerical value of write pointer register adds being uneven in length in the numerical value of read pointer register of data message; Then message is stored on the offset address at numerical value place of the write pointer register in the buffering area, and writes in the write pointer register after the numerical value of write pointer register being added the total length of message.
When network interface card sends message; Read pointer register and write pointer register are compared; If the numerical value of read pointer register is not equal to the numerical value of write pointer register; Then the offset address with the numerical value of read pointer register in buffering area formation place carries out the message transmit operation as heading, and writes in the read pointer register after the numerical value of read pointer register being added the total length of message.
Fig. 2 is the block diagram that is used for the processing unit of network data in zero-copy buffer queue transmission according to of the present invention.
As shown in Figure 2, the processing unit that is used for the network data in zero-copy buffer queue transmission according to the present invention comprises: internal memory application unit 202 is used for being used in the contiguous memory conduct of the predetermined size of NIC driver application the buffering area formation of message transmission; Converting unit 204 is used for first address with the contiguous memory of being applied for and converts physical address into and store the size of physical address and internal memory into the network interface card related register; And register setting and updating block 206; Be used for being provided for the read pointer register and the write pointer register of buffering area formation at the network interface card register; When sending message, the size renewal read pointer register and the write pointer register of message, physical address and the internal memory that will send according to institute.
Wherein, can specify the size of the contiguous memory of being applied for, the size of the contiguous memory that also can when driver loads, be applied for through the parameter appointment through configuration file.
When application program is sent message; Register setting and updating block compare read pointer register and write pointer register; If the numerical value of write pointer register adds data message and is uneven in length in the numerical value of read pointer register; Then message is stored on the offset address at numerical value place of the write pointer register in the buffering area, and writes in the write pointer register after the numerical value of write pointer register being added the total length of message.
When network interface card sends message; Register setting and updating block compare read pointer register and write pointer register; If the numerical value of read pointer register is not equal to the numerical value of write pointer register; Then the offset address with the numerical value of read pointer register in buffering area formation place carries out the message transmit operation as heading, and writes in the read pointer register after the numerical value of read pointer register being added the total length of message.
Fig. 3 is the flow chart that is used for the processing method of network data in zero-copy buffer queue reception according to of the present invention.
As shown in Figure 3, the processing method that is used for the network data in zero-copy buffer queue reception according to the present invention may further comprise the steps:
Step S302, the contiguous memory of the predetermined size of application is as being used for the buffering area formation that message receives in NIC driver;
Step S304 converts the first address of the contiguous memory of being applied for physical address into and the size of physical address and internal memory is stored in the network interface card related register; And
Step S306 is provided for the read pointer register and the write pointer register of buffering area formation in the network interface card register, when receiving message, upgrade read pointer register and write pointer register according to the size of the message that is received, physical address and internal memory.
Wherein, can specify the size of the contiguous memory of being applied for, the size of the contiguous memory that also can when driver loads, be applied for through the parameter appointment through configuration file.Size need confirm according to the memory size of computer, 32MB for example, 64MB etc.Network interface card register itself can be the memory headroom of storage 32 figure places.Wherein, the network interface card related register can be for receiving buffering area first address configuration register, and receiving buffering area first address configuration register can be 64 sizes.
Between the application program of driver and user's operation, there is a function interface storehouse that application program can be called.The purpose in function interface storehouse is to make things convenient for the inside of writing and shield driver and network card equipment of user application to realize.Therefore, can pass through the application program update read pointer register, and upgrade the write pointer register through network interface card.
When application program receives message; Read pointer register and write pointer register are compared; If the numerical value of read pointer register is not equal to the numerical value of write pointer register, then the offset address with the numerical value of read pointer register in buffering area formation place returns to application program as heading.
When network interface card receives message; Read pointer register and write pointer register are compared; If the numerical value of write pointer register adds data message and is uneven in length in read pointer register; Then message is stored on the offset address at numerical value place of the write pointer register in the buffering area, and writes in the write pointer register after the numerical value of write pointer register being added the total length of message.
Fig. 4 is the block diagram that is used for the processing unit of network data in zero-copy buffer queue reception according to of the present invention.
As shown in Figure 4, the processing unit that is used for the network data in zero-copy buffer queue reception according to the present invention comprises: internal memory application unit 402 is used for being used in the contiguous memory conduct of the predetermined size of NIC driver application the buffering area formation of message reception; Converting unit 404 is used for first address with the contiguous memory of being applied for and converts physical address into and store the size of physical address and internal memory into the network interface card related register; Register is provided with and updating block 406; Be used for being provided for the read pointer register and the write pointer register of buffering area formation at the network interface card register; And when receiving message, upgrade read pointer register and write pointer register according to the size of the message that is received, physical address and internal memory.
Wherein, internal memory application unit can be specified the size of the contiguous memory of being applied for through configuration file, also can specify the size of the contiguous memory of being applied for through when driver loads, utilizing parameter.Size need confirm according to the memory size of computer, 32MB for example, 64MB etc.Network interface card register itself can be the memory headroom of storage 32 figure places.Wherein, the network interface card related register can be for receiving buffering area first address configuration register, and receiving buffering area first address configuration register can be 64 sizes.
When application program receives message; Register setting and updating block compare read pointer register and write pointer register; If the numerical value of read pointer register is not equal to the numerical value of write pointer register, then the offset address with the numerical value of read pointer register in buffering area formation place returns to application program as heading.
When network interface card receives message; Register setting and updating block compare read pointer register and write pointer register; If the numerical value of write pointer register adds data message and is uneven in length in read pointer register; Then message is stored on the offset address at numerical value place of the write pointer register in the buffering area, and writes in the write pointer register after the numerical value of write pointer register being added the total length of message.
In sum; By above-mentioned at least one technical scheme of the present invention; Through applying for that continuous internal memory is as the buffering area formation of sending or receive message; Convert the first address of the internal memory of being applied for to physical address and store in the related register, and when sending or receive message, upgrade the pointer position in the related register in time, can realize following technique effect:
(1) network interface card need not adopt interrupt mode notice driver data message to send or finish receiving situation, does not take cpu resource;
(2) need not convert the user's space memory address to dma operation required physical address by page-size;
(3) network interface card hardware when storing, is not limited by page-size, such as the 4K byte at the data message of doing dma operation and transmission;
(4) need not use buffer descriptor to carry out the management of buffering area formation.
Obviously, it is apparent to those skilled in the art that above-mentioned each module of the present invention or each step can realize with the general calculation device; They can concentrate on the single calculation element; Perhaps be distributed on the network that a plurality of calculation element forms, alternatively, they can be realized with the executable program code of calculation element; Thereby; Can they be stored in the storage device and carry out, perhaps they are made into each integrated circuit modules respectively, perhaps a plurality of modules in them or step are made into the single integrated circuit module and realize by calculation element.Like this, the present invention is not restricted to any specific hardware and software combination.
The above is merely the preferred embodiments of the present invention, is not limited to the present invention, and for a person skilled in the art, the present invention can have various changes and variation.All within spirit of the present invention and principle, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.